<!DOCTYPE html>
<html lang=zh>
<head>
    <!-- so meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="HandheldFriendly" content="True">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="description" content="设置中文在导航栏选择 Options-&gt;Choose Language-&gt;Chinese(Simplified) 即可设置为简体中文 设置后如下图 设置请求头 新增HTTP信息头管理器  逐个设置请求头即可，如果我们是post请求想要设置请求参数为json数据则可以添加Content-Type，值为application&#x2F;json   设置请求默认值 以百度搜索为例，新增 HTTP请求">
<meta property="og:type" content="article">
<meta property="og:title" content="JMeter 测试常用到的一些功能">
<meta property="og:url" content="https:&#x2F;&#x2F;fengzxia.gitee.io&#x2F;posts&#x2F;fd807af5.html">
<meta property="og:site_name" content="只是学习学习的博客">
<meta property="og:description" content="设置中文在导航栏选择 Options-&gt;Choose Language-&gt;Chinese(Simplified) 即可设置为简体中文 设置后如下图 设置请求头 新增HTTP信息头管理器  逐个设置请求头即可，如果我们是post请求想要设置请求参数为json数据则可以添加Content-Type，值为application&#x2F;json   设置请求默认值 以百度搜索为例，新增 HTTP请求">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvQllOZjRuQWIyNUVyaVJvLnBuZw">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvVU10YkFObmM4WXpmUEZtLnBuZw">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvZDZHdkJEZlRxSUpQZUNILnBuZw">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvaDVSZzZrREFhUU9MenRILnBuZw">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvSERHSnI4NnFtWlJMd2Z6LnBuZw">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUva0FESlNNZ1QxVWx0N3M2LnBuZw?x-oss-process&#x3D;image&#x2F;format,png">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvOXhxNGxySDZ1SzVNTkQ4LnBuZw">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvZk5lcnVhbDVFeWlNdFFrLnBuZw">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvUDRhVXI3bmo1SWtPZTF5LnBuZw">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvSGROcndTUjZJZU8zWjl0LnBuZw">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvT0kxVXJSRU1vWEZXS3dlLnBuZw">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvSGt5M1F6U0JGRFVDdjJWLnBuZw">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvbHpUTm9yREY3UmV1bTNnLnBuZw">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvYmNxVjhhMTVPdTk2SEF0LnBuZw">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvVlJEWU01cEFxcldpYjNQLnBuZw">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FM1BuVS5wbmc">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FM0c0QS5wbmc">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FR3BlVS5wbmc">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FR2VPSy5wbmc">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FZGIyNC5wbmc">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FYTl3Ni5wbmc">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FMEtUeC5wbmc">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FMGhOVi5wbmc">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FQjlqSC5wbmc">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FQmhxQS5wbmc">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FQnphcS5wbmc">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FREFzSi5wbmc">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FSmlCOC5wbmc">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FSnVqMC5wbmc">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FSjZDZC5wbmc">
<meta property="og:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FdHk2SS5wbmc">
<meta property="article:published_time" content="2019-08-15T09:04:14.000Z">
<meta property="article:modified_time" content="2020-04-16T12:11:10.371Z">
<meta property="article:author" content="只是学习学习">
<meta property="article:tag" content="测试">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https:&#x2F;&#x2F;imgconvert.csdnimg.cn&#x2F;aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvQllOZjRuQWIyNUVyaVJvLnBuZw">
    
    
        
          
              <link rel="shortcut icon" href="/images/favicon.ico">
          
        
        
          
            <link rel="icon" type="image/png" href="/images/favicon-192x192.png" sizes="192x192">
          
        
        
          
            <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
          
        
    
    <!-- title -->
    <title>JMeter 测试常用到的一些功能</title>
    <!-- styles -->
    
<link rel="stylesheet" href="/css/style.css">

    <!-- persian styles -->
    
      
<link rel="stylesheet" href="/css/rtl.css">

    
    <!-- rss -->
    
    
    
<meta name="generator" content="Hexo 4.1.1"></head>

<body class="max-width mx-auto px3 ltr">
    
      <div id="header-post">
  <a id="menu-icon" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="menu-icon-tablet" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="top-icon-tablet" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');" style="display:none;"><i class="fas fa-chevron-up fa-lg"></i></a>
  <span id="menu">
    <span id="nav">
      <ul>
         
          <li><a href="/">主页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/categories/">分类</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/about/">关于</a></li>
         
          <li><a href="/friend_ship/">友链</a></li>
        
      </ul>
    </span>
    <br/>
    <span id="actions">
      <ul>
        
        <li><a class="icon" href="/posts/1950a942.html"><i class="fas fa-chevron-left" aria-hidden="true" onmouseover="$('#i-prev').toggle();" onmouseout="$('#i-prev').toggle();"></i></a></li>
        
        
        <li><a class="icon" href="/posts/a49a18a1.html"><i class="fas fa-chevron-right" aria-hidden="true" onmouseover="$('#i-next').toggle();" onmouseout="$('#i-next').toggle();"></i></a></li>
        
        <li><a class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up" aria-hidden="true" onmouseover="$('#i-top').toggle();" onmouseout="$('#i-top').toggle();"></i></a></li>
        <li><a class="icon" href="#"><i class="fas fa-share-alt" aria-hidden="true" onmouseover="$('#i-share').toggle();" onmouseout="$('#i-share').toggle();" onclick="$('#share').toggle();return false;"></i></a></li>
      </ul>
      <span id="i-prev" class="info" style="display:none;">上一篇</span>
      <span id="i-next" class="info" style="display:none;">下一篇</span>
      <span id="i-top" class="info" style="display:none;">返回顶部</span>
      <span id="i-share" class="info" style="display:none;">分享文章</span>
    </span>
    <br/>
    <div id="share" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=https://fengzxia.gitee.io/posts/fd807af5.html" target="_blank" rel="noopener"><i class="fab fa-facebook " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=https://fengzxia.gitee.io/posts/fd807af5.html&text=JMeter 测试常用到的一些功能" target="_blank" rel="noopener"><i class="fab fa-twitter " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=https://fengzxia.gitee.io/posts/fd807af5.html&title=JMeter 测试常用到的一些功能" target="_blank" rel="noopener"><i class="fab fa-linkedin " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=https://fengzxia.gitee.io/posts/fd807af5.html&is_video=false&description=JMeter 测试常用到的一些功能" target="_blank" rel="noopener"><i class="fab fa-pinterest " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=JMeter 测试常用到的一些功能&body=Check out this article: https://fengzxia.gitee.io/posts/fd807af5.html"><i class="fas fa-envelope " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=https://fengzxia.gitee.io/posts/fd807af5.html&title=JMeter 测试常用到的一些功能" target="_blank" rel="noopener"><i class="fab fa-get-pocket " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=https://fengzxia.gitee.io/posts/fd807af5.html&title=JMeter 测试常用到的一些功能" target="_blank" rel="noopener"><i class="fab fa-reddit " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=https://fengzxia.gitee.io/posts/fd807af5.html&title=JMeter 测试常用到的一些功能" target="_blank" rel="noopener"><i class="fab fa-stumbleupon " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=https://fengzxia.gitee.io/posts/fd807af5.html&title=JMeter 测试常用到的一些功能" target="_blank" rel="noopener"><i class="fab fa-digg " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=https://fengzxia.gitee.io/posts/fd807af5.html&name=JMeter 测试常用到的一些功能&description=" target="_blank" rel="noopener"><i class="fab fa-tumblr " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://news.ycombinator.com/submitlink?u=https://fengzxia.gitee.io/posts/fd807af5.html&t=JMeter 测试常用到的一些功能" target="_blank" rel="noopener"><i class="fab fa-hacker-news " aria-hidden="true"></i></a></li>
</ul>

    </div>
    <div id="toc">
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#设置中文"><span class="toc-number">1.</span> <span class="toc-text">设置中文</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#设置请求头"><span class="toc-number">2.</span> <span class="toc-text">设置请求头</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#设置请求默认值"><span class="toc-number">3.</span> <span class="toc-text">设置请求默认值</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#设置普通变量并使用"><span class="toc-number">4.</span> <span class="toc-text">设置普通变量并使用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#设置随机数变量并使用"><span class="toc-number">5.</span> <span class="toc-text">设置随机数变量并使用</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#其他写法"><span class="toc-number">5.1.</span> <span class="toc-text">其他写法</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#读取csv文件"><span class="toc-number">6.</span> <span class="toc-text">读取csv文件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#获取到上一个方法的返回值，并设置为变量"><span class="toc-number">7.</span> <span class="toc-text">获取到上一个方法的返回值，并设置为变量</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#逻辑判断"><span class="toc-number">8.</span> <span class="toc-text">逻辑判断</span></a></li></ol>
    </div>
  </span>
</div>

    
    <div class="content index py4">
        
        <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
  <header>
    
    <h1 class="posttitle" itemprop="name headline">
        JMeter 测试常用到的一些功能
    </h1>



    <div class="meta">
      <span class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
        <span itemprop="name">只是学习学习的博客</span>
      </span>
      
    <div class="postdate">
      
        <time datetime="2019-08-15T09:04:14.000Z" itemprop="datePublished">2019-08-15</time>
        
      
    </div>


      
    <div class="article-category">
        <i class="fas fa-archive"></i>
        <a class="category-link" href="/categories/%E6%B5%8B%E8%AF%95/">测试</a> › <a class="category-link" href="/categories/%E6%B5%8B%E8%AF%95/JMeter/">JMeter</a>
    </div>


      
    <div class="article-tag">
        <i class="fas fa-tag"></i>
        <a class="tag-link" href="/tags/%E6%B5%8B%E8%AF%95/" rel="tag">测试</a>
    </div>


    </div>
  </header>
  

  <div class="content"itemprop ="articleBody">
    <h2 id="设置中文"><a href="#设置中文" class="headerlink" title="设置中文"></a>设置中文</h2><p>在导航栏选择 <code>Options-&gt;Choose Language-&gt;Chinese(Simplified)</code> 即可设置为简体中文<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvQllOZjRuQWIyNUVyaVJvLnBuZw" alt="UTOOLS1565849537890.png"></p>
<p>设置后如下图<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvVU10YkFObmM4WXpmUEZtLnBuZw" alt="UTOOLS1565849659132.png"></p>
<h2 id="设置请求头"><a href="#设置请求头" class="headerlink" title="设置请求头"></a>设置请求头</h2><ol>
<li><p>新增<code>HTTP信息头管理器</code><br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvZDZHdkJEZlRxSUpQZUNILnBuZw" alt="UTOOLS1565850836742.png"></p>
</li>
<li><p>逐个设置请求头即可，如果我们是post请求想要设置请求参数为json数据则可以添加<code>Content-Type</code>，值为<code>application/json</code><br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvaDVSZzZrREFhUU9MenRILnBuZw" alt="UTOOLS1565850960112.png"></p>
</li>
</ol>
<h2 id="设置请求默认值"><a href="#设置请求默认值" class="headerlink" title="设置请求默认值"></a>设置请求默认值</h2><ol>
<li><p>以百度搜索为例，新增 <code>HTTP请求默认值</code><br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvSERHSnI4NnFtWlJMd2Z6LnBuZw" alt="UTOOLS1565851069666.png"></p>
</li>
<li><p>然后直接设置请求的域名，协议，端口等信息<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUva0FESlNNZ1QxVWx0N3M2LnBuZw?x-oss-process=image/format,png" alt="test.png"></p>
</li>
<li><p>在发送http请求时，如果不设置这些信息，则会使用默认的<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvOXhxNGxySDZ1SzVNTkQ4LnBuZw" alt="UTOOLS1565851866506.png"><br>[外链图片转存失败(img-l6LecNDL-1565859654765)(<a href="https://i.loli.net/2019/08/15/8NU796HhzXFf2LI.png)]" target="_blank" rel="noopener">https://i.loli.net/2019/08/15/8NU796HhzXFf2LI.png)]</a></p>
</li>
</ol>
<h2 id="设置普通变量并使用"><a href="#设置普通变量并使用" class="headerlink" title="设置普通变量并使用"></a>设置普通变量并使用</h2><ol>
<li><p>还是以百度搜索为例，右键测试计划新增一个用户自定义配置元件<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvZk5lcnVhbDVFeWlNdFFrLnBuZw" alt="UTOOLS1565851630729.png"></p>
</li>
<li><p>添加查询条件参数<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvUDRhVXI3bmo1SWtPZTF5LnBuZw" alt="UTOOLS1565852073658.png"></p>
</li>
<li><p>新建一个http请求，通过<code>${参数名}</code>的方式来获取参数<br>[外链图片转存失败(img-NMfrhBcJ-1565859654772)(<a href="https://i.loli.net/2019/08/15/NsrBmJQ36SaoMly.png)]" target="_blank" rel="noopener">https://i.loli.net/2019/08/15/NsrBmJQ36SaoMly.png)]</a></p>
</li>
<li><p>启动查看结果，可以看到在http的名称和参数中都能获取到该参数</p>
</li>
</ol>
<h2 id="设置随机数变量并使用"><a href="#设置随机数变量并使用" class="headerlink" title="设置随机数变量并使用"></a>设置随机数变量并使用</h2><ol>
<li><p>右键选择测试计划创建<code>随机变量</code>配置元件<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvSGROcndTUjZJZU8zWjl0LnBuZw" alt="UTOOLS1565852293655.png"></p>
<p> <img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvT0kxVXJSRU1vWEZXS3dlLnBuZw" alt="UTOOLS1565853158742.png"></p>
</li>
<li><p>创建两个设置参数，和之前设置普通的一样<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvSGt5M1F6U0JGRFVDdjJWLnBuZw" alt="UTOOLS1565854457673.png"></p>
</li>
<li><p>执行JMeter查看返回的随机数<br>[外链图片转存失败(img-6PmCqJqf-1565859654778)(<a href="https://i.loli.net/2019/08/15/7dxCbzR6y39sfhE.png)]" target="_blank" rel="noopener">https://i.loli.net/2019/08/15/7dxCbzR6y39sfhE.png)]</a></p>
</li>
</ol>
<h3 id="其他写法"><a href="#其他写法" class="headerlink" title="其他写法"></a>其他写法</h3><ol>
<li><p>添加3个用户自定义变量<br>[外链图片转存失败(img-fIOIZh10-1565859654779)(<a href="https://i.loli.net/2019/08/15/kO8fNguiaybmnrF.png)]" target="_blank" rel="noopener">https://i.loli.net/2019/08/15/kO8fNguiaybmnrF.png)]</a></p>
</li>
<li><p>使用<code>${__V(wd${__Random(1, 3)})}</code>调用<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvbHpUTm9yREY3UmV1bTNnLnBuZw" alt="UTOOLS1565854923990.png"></p>
</li>
<li><p>拆解</p>
<ul>
<li><code>${__Random(1, 3)}</code>: 随机生成1-3之间的整数  </li>
<li><code>wd${__Random(1, 3)}</code>: 随机生成wd1, wd2, wd3中的任意1个字符串</li>
<li><code>${__V(wd${__Random(1, 3)})}</code>: 对形如wd1的字符串求值。也就是不把wd1当成字符串来看，而是把wd1当作是1个变量，并获取这个变量的值。wd1的值是我们在用户自定义变量中定义过的，也就是搜索。那么连起来，这个表达式的作用就是随机生成搜索第一个变量, 搜索第二个变量, 搜索第三个变量中的任意一个字符串</li>
</ul>
</li>
<li><p>请求的结果如下<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvYmNxVjhhMTVPdTk2SEF0LnBuZw" alt="UTOOLS1565855258378.png"></p>
</li>
<li><p>可以看到在http请求，名称中的参数和发送请求时wd的参数值不一样，即每次都请求都不一样</p>
</li>
</ol>
<p><strong>由于随机数的生成的时候会耗cpu和内存，当用户量并发量很大的时候，不推荐使用JMeter脚本来生成随机数，这个时候推荐使用下边的方法通过读取csv文件来获取请求的值</strong></p>
<h2 id="读取csv文件"><a href="#读取csv文件" class="headerlink" title="读取csv文件"></a>读取csv文件</h2><ol>
<li>创建txt文件 输入如下内容，另存为csv文件（编码为UTF-8），每次在txt文档修改保存 每组数据以英文逗号分隔<br>[外链图片转存失败(img-2CcqEAmE-1565859654788)(<a href="https://i.loli.net/2019/08/15/MBHEJ14QfiFTLuO.png)]" target="_blank" rel="noopener">https://i.loli.net/2019/08/15/MBHEJ14QfiFTLuO.png)]</a></li>
</ol>
<p><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9pLmxvbGkubmV0LzIwMTkvMDgvMTUvVlJEWU01cEFxcldpYjNQLnBuZw" alt="UTOOLS1565855742052.png"></p>
<ol start="2">
<li><p>创建csv数据文件设置<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FM1BuVS5wbmc" alt="mE3PnU.png"></p>
<p><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FM0c0QS5wbmc" alt="mE3G4A.png"><br>title和value代表每行有两列数据（名字可以自己随便定义），把读取到的2个数据分别赋值给title和value(循环一次使用第一行数据，循环两次使用第二行数据，以此类推，超出则从第一行开始重新获取)</p>
</li>
<li><p>使用变量还是和之前一样，可以看到参数设置成功<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FR3BlVS5wbmc" alt="mEGpeU.png"><br>请求结果<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FR2VPSy5wbmc" alt="mEGeOK.png"></p>
</li>
</ol>
<h2 id="获取到上一个方法的返回值，并设置为变量"><a href="#获取到上一个方法的返回值，并设置为变量" class="headerlink" title="获取到上一个方法的返回值，并设置为变量"></a>获取到上一个方法的返回值，并设置为变量</h2><p>在返回值为json数据是常用到，以京东的评论接口为例</p>
<ol>
<li><p>因为京东有接口限制，所以我们要新添加<code>Content-Type</code>和<code>Referer</code>这两个请求头<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FZGIyNC5wbmc" alt="mEdb24.png"></p>
</li>
<li><p>新建一个http请求设置接口和参数<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FYTl3Ni5wbmc" alt="mEa9w6.png"></p>
</li>
<li><p>对接口进行请求，先尝试对返回结果进行提取</p>
<ul>
<li>在<code>查看结果树</code>中先将返回值换为json格式查看<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FMEtUeC5wbmc" alt="mE0KTx.png"></li>
<li>然后在<code>JSON Path Expression</code>后的数据框中输入提取字段方法测试，例如提去热门标签中的第一个名字，点击test测试是否能获取到<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FMGhOVi5wbmc" alt="mE0hNV.png"></li>
<li><code>$.</code>: 是固定开头，后边根据对象层级通过<code>.</code>来获取</li>
</ul>
</li>
<li><p>右键在第二步中添加http请求，选择后置处理器添加<code>JSON Extractor</code><br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FQjlqSC5wbmc" alt="mEB9jH.png"></p>
</li>
<li><p>在<code>JSON Extractor</code>提取到需要的值，并设置参数名<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FQmhxQS5wbmc" alt="mEBhqA.png"></p>
</li>
<li><p>右键线程组添加<code>Debug Sampler</code>调试取样器，来查看是否获取成功<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FQnphcS5wbmc" alt="mEBzaq.png"></p>
</li>
<li><p>执行JMeter，可以看到设置成功<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FREFzSi5wbmc" alt="mEDAsJ.png"></p>
</li>
</ol>
<h2 id="逻辑判断"><a href="#逻辑判断" class="headerlink" title="逻辑判断"></a>逻辑判断</h2><ol>
<li><p>右键线程组添加（if）选择控制器<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FSmlCOC5wbmc" alt="mEJiB8.png"></p>
<p>设置当<code>${value}</code>值为<code>JMeter2</code>时才执行<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FSnVqMC5wbmc" alt="mEJuj0.png"></p>
</li>
<li><p>右键(if)选择控制器，来新增一个http请求，不填任何数据使用默认值<br><img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FSjZDZC5wbmc" alt="mEJ6Cd.png"><br><strong>注: 要将下边的<code>Interpret Condition as Variable Expression?</code> 选框勾选去掉，否则无法通过<code>${value}</code>获取到参数值，而是将<code>${value}</code>当做字符串比较</strong></p>
</li>
<li><p>启动JMeter查看返回结果，只有<code>value</code>为<code>JMeter2</code>时才执行了<code>进入if判断</code>请求   <img src="https://imgconvert.csdnimg.cn/aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA4LzE1L21FdHk2SS5wbmc" alt="mEty6I.png"></p>
</li>
</ol>

<div id="gitalk-container"></div>
<script src="https://cdn.bootcss.com/blueimp-md5/2.12.0/js/md5.min.js"></script><link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css"><script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>

		<script>
		var gitalkConfig = {"clientID":"28a065e3b5afee156f4f","clientSecret":"e18104d6f3219526491fc42c892ff6a26b8f3e74","repo":"blog_comment","owner":"FENG1000","admin":["FENG1000"],"distractionFreeMode":false};
	    gitalkConfig.id = md5(location.pathname);
		var gitalk = new Gitalk(gitalkConfig);
	    gitalk.render("gitalk-container");
	    </script>
    
  <blockquote>
      <p>
          作者: 只是学习学习<br>
          邮箱: fengzxia1000@163.com<br>
          原文地址: <a href="https://fengzxia.gitee.io/posts/fd807af5.html" target="_blank" rel="noopener">https://fengzxia.gitee.io/posts/fd807af5.html</a><br>
          版权声明: 商业转载请联系作者获得授权，非商业转载请注明出处。
      </p>
  </blockquote>

  <script>
      function setClipboardText(event){
          // clipboardData 对象是为通过编辑菜单、快捷菜单和快捷键执行的编辑操作所保留的，也就是你复制或者剪切内容
          let clipboardData = event.clipboardData || window.clipboardData;
          // 如果未复制或者未剪切，则return出去
          if (!clipboardData) { return; }
          event.preventDefault();
          // Selection 对象，表示用户选择的文本范围或光标的当前位置。
          //     声明一个变量接收 -- 用户输入的剪切或者复制的文本转化为字符串
          let text = window.getSelection().toString();

          if (text) {
            // 如果文本存在则先取消文本默认事件
            event.preventDefault();
            // 通过调用常clipboardData对象的 setData(format, data) 方法；来设置相关文本
            // format: 一个DOMString 表示要添加到 drag object的拖动数据的类型。
            // data: 一个 DOMString表示要添加到 drag object的数据。
            var copyright = '\n\n'
                            + '\n著作权归作者所有。'
                            + '\n商业转载请联系作者获得授权，非商业转载请注明出处。'
                            + '\n作者: 只是学习学习'
                            + '\n邮箱: fengzxia1000@163.com'
                            + '\n原文地址: https://fengzxia.gitee.io/posts/fd807af5.html'

            clipboardData.setData('text/plain', text + copyright);

          }
      };
      var contents = document.getElementsByClassName("content");
      // 监听文章内容的copy事件
      contents[0].addEventListener('copy',function(e){
          setClipboardText(e);
      });
  </script>

  </div>
</article>




        
          <div id="footer-post-container">
  <div id="footer-post">

    <div id="nav-footer" style="display: none">
      <ul>
         
          <li><a href="/">主页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/categories/">分类</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/about/">关于</a></li>
         
          <li><a href="/friend_ship/">友链</a></li>
        
      </ul>
    </div>

    <div id="toc-footer" style="display: none">
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#设置中文"><span class="toc-number">1.</span> <span class="toc-text">设置中文</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#设置请求头"><span class="toc-number">2.</span> <span class="toc-text">设置请求头</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#设置请求默认值"><span class="toc-number">3.</span> <span class="toc-text">设置请求默认值</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#设置普通变量并使用"><span class="toc-number">4.</span> <span class="toc-text">设置普通变量并使用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#设置随机数变量并使用"><span class="toc-number">5.</span> <span class="toc-text">设置随机数变量并使用</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#其他写法"><span class="toc-number">5.1.</span> <span class="toc-text">其他写法</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#读取csv文件"><span class="toc-number">6.</span> <span class="toc-text">读取csv文件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#获取到上一个方法的返回值，并设置为变量"><span class="toc-number">7.</span> <span class="toc-text">获取到上一个方法的返回值，并设置为变量</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#逻辑判断"><span class="toc-number">8.</span> <span class="toc-text">逻辑判断</span></a></li></ol>
    </div>

    <div id="share-footer" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=https://fengzxia.gitee.io/posts/fd807af5.html" target="_blank" rel="noopener"><i class="fab fa-facebook fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=https://fengzxia.gitee.io/posts/fd807af5.html&text=JMeter 测试常用到的一些功能" target="_blank" rel="noopener"><i class="fab fa-twitter fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=https://fengzxia.gitee.io/posts/fd807af5.html&title=JMeter 测试常用到的一些功能" target="_blank" rel="noopener"><i class="fab fa-linkedin fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=https://fengzxia.gitee.io/posts/fd807af5.html&is_video=false&description=JMeter 测试常用到的一些功能" target="_blank" rel="noopener"><i class="fab fa-pinterest fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=JMeter 测试常用到的一些功能&body=Check out this article: https://fengzxia.gitee.io/posts/fd807af5.html"><i class="fas fa-envelope fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=https://fengzxia.gitee.io/posts/fd807af5.html&title=JMeter 测试常用到的一些功能" target="_blank" rel="noopener"><i class="fab fa-get-pocket fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=https://fengzxia.gitee.io/posts/fd807af5.html&title=JMeter 测试常用到的一些功能" target="_blank" rel="noopener"><i class="fab fa-reddit fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=https://fengzxia.gitee.io/posts/fd807af5.html&title=JMeter 测试常用到的一些功能" target="_blank" rel="noopener"><i class="fab fa-stumbleupon fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=https://fengzxia.gitee.io/posts/fd807af5.html&title=JMeter 测试常用到的一些功能" target="_blank" rel="noopener"><i class="fab fa-digg fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=https://fengzxia.gitee.io/posts/fd807af5.html&name=JMeter 测试常用到的一些功能&description=" target="_blank" rel="noopener"><i class="fab fa-tumblr fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://news.ycombinator.com/submitlink?u=https://fengzxia.gitee.io/posts/fd807af5.html&t=JMeter 测试常用到的一些功能" target="_blank" rel="noopener"><i class="fab fa-hacker-news fa-lg" aria-hidden="true"></i></a></li>
</ul>

    </div>

    <div id="actions-footer">
        <a id="menu" class="icon" href="#" onclick="$('#nav-footer').toggle();return false;"><i class="fas fa-bars fa-lg" aria-hidden="true"></i> 菜单</a>
        <a id="toc" class="icon" href="#" onclick="$('#toc-footer').toggle();return false;"><i class="fas fa-list fa-lg" aria-hidden="true"></i> 目录</a>
        <a id="share" class="icon" href="#" onclick="$('#share-footer').toggle();return false;"><i class="fas fa-share-alt fa-lg" aria-hidden="true"></i> 分享</a>
        <a id="top" style="display:none" class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up fa-lg" aria-hidden="true"></i> 返回顶部</a>
    </div>

  </div>
</div>

        
        <footer id="footer">
  <div class="footer-left">
    Copyright &copy;
    
    
    2019-2020
    只是学习学习
  </div>
  <div class="footer-right">
    <nav>
      <ul>
         
          <li><a href="/">主页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/categories/">分类</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/about/">关于</a></li>
         
          <li><a href="/friend_ship/">友链</a></li>
        
      </ul>
    </nav>
  </div>
</footer>

    </div>
    <!-- styles -->

<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">


<link rel="stylesheet" href="/lib/justified-gallery/css/justifiedGallery.min.css">


    <!-- jquery -->

<script src="/lib/jquery/jquery.min.js"></script>


<script src="/lib/justified-gallery/js/jquery.justifiedGallery.min.js"></script>

<!-- clipboard -->

  
<script src="/lib/clipboard/clipboard.min.js"></script>

  <script type="text/javascript">
  $(function() {
    // copy-btn HTML
    var btn = "<span class=\"btn-copy tooltipped tooltipped-sw\" aria-label=\"复制到粘贴板!\">";
    btn += '<i class="far fa-clone"></i>';
    btn += '</span>'; 
    // mount it!
    $(".highlight table").before(btn);
    var clip = new ClipboardJS('.btn-copy', {
      text: function(trigger) {
        return Array.from(trigger.nextElementSibling.querySelectorAll('.code')).reduce((str,it)=>str+it.innerText+'\n','')
      }
    });
    clip.on('success', function(e) {
      e.trigger.setAttribute('aria-label', "复制成功!");
      e.clearSelection();
    })
  })
  </script>


<script src="/js/main.js"></script>

<!-- search -->

<!-- Google Analytics -->

<!-- Baidu Analytics -->

    <script type="text/javascript">
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?54382acbd8c4bc66535bce135e0ac166";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>

<!-- Disqus Comments -->


</body>
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https'){
   bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
  }
  else{
  bp.src = 'http://push.zhanzhang.baidu.com/push.js';
  }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>
</html>
